package com.atguigu.test.mvc.my;

import com.atguigu.test.mvc.annotation.Token;
import com.atguigu.test.po.User;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.yaml.snakeyaml.Yaml;

/**
 * @author zp
 * @version 1.0
 * @description: 自定义的参数解析器 针对的是@Token注解
 * @date 2023/1/2 16:01
 */
public class MyTokenHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
    // 是否支持某些参数或者注解
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        if (parameter.hasParameterAnnotation(Token.class)) {
            return true;
        }
        return false;
    }
    // 解析参数的具体逻辑方法
    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        return webRequest.getHeader("token");
    }
}
